package MainGUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import chat.ChatServer;




/*
 * SeverGUI.java
 *
 * Created on 25-Apr-2012, 12:26:54
 */
/**
 *
 * @author bwb09141
 */
public class MainServerGUI extends javax.swing.JFrame implements Runnable {

    ChatServer chat;
    boolean chatActive;
	
    /** Creates new form SeverGUI */
    public MainServerGUI() {
        initComponents();
    }
    
    /** Creates new form SeverGUI */
    public MainServerGUI(ChatServer chat) {
        initComponents();
        this.chat = chat;
        chatActive = true;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        Start = new javax.swing.JButton();
        Stop = new javax.swing.JButton();
        Chat_Scroll = new javax.swing.JScrollPane();
        Chat_Text_Area = new javax.swing.JTextArea();
        RTSP_Scroll = new javax.swing.JScrollPane();
        RTSP_Text_Area = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        jLabel2.setText("jLabel2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        Start.setText("Start");
        
        Start.addActionListener(new ActionListener()
			{
				@Override
				public void actionPerformed(ActionEvent ev) {
					
				}
			});

        Stop.setText("Stop");
        
        Stop.addActionListener(new ActionListener()
			{
				@Override
				public void actionPerformed(ActionEvent ev) {
					if(chatActive){
						chat.shutDown();
						chatActive = false;
					}
				}
			});

        Chat_Text_Area.setColumns(20);
        Chat_Text_Area.setRows(5);
        Chat_Text_Area.setEditable(false);
        Chat_Text_Area.setLineWrap(true);
        Chat_Scroll.setViewportView(Chat_Text_Area);

        RTSP_Text_Area.setColumns(20);
        RTSP_Text_Area.setRows(5);
        RTSP_Text_Area.setEditable(false);
        RTSP_Scroll.setViewportView(RTSP_Text_Area);

        jLabel1.setText("Chat server");

        jLabel3.setText("RTSP");
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Start)
                        .addGap(18, 18, 18)
                        .addComponent(Stop))
                    .addComponent(Chat_Scroll, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addComponent(RTSP_Scroll, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(jLabel3))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Start)
                    .addComponent(Stop))
                .addGap(19, 19, 19)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Chat_Scroll, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(RTSP_Scroll, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(89, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new MainServerGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JScrollPane Chat_Scroll;
    private javax.swing.JTextArea Chat_Text_Area;
    private javax.swing.JScrollPane RTSP_Scroll;
    private javax.swing.JTextArea RTSP_Text_Area;
    private javax.swing.JButton Start;
    private javax.swing.JButton Stop;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration
    
    /**
     * Update chat server text field in the GUI. 
     * @param update String to update
     */
    public void updateChatString(String update){
    	Chat_Text_Area.append(update);
    }
    
    /**
     * Update RTSP server text field in the GUI.
     * @param update String to update
     */
    public void updateRTSPString(String update){
    	RTSP_Text_Area.append(update);
    }

	@Override
	public void run() {
		while(true){
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
}